package com.ztz.mynewdemo.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.ztz.mynewdemo.R;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by wqewqe on 2017/12/20.
 */

public class zhuKuAdapter extends RecyclerView.Adapter<zhuKuAdapter.ViewHolder> {
    Context context;
    ArrayList<String> titles;
    ArrayList<String> imgUris;
    ArrayList<String> smTitles;

    public zhuKuAdapter(Context context, ArrayList<String> titles, ArrayList<String> imgUris, ArrayList<String> smTitles) {
        this.context = context;
        this.titles = titles;
        this.imgUris = imgUris;
        this.smTitles = smTitles;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_zhuku, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        Glide.with(context).load(imgUris.get(position))
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .centerCrop()
                .into(holder.iv);
        holder.tvTitle.setText(titles.get(position));
        holder.tvType.setText(smTitles.get(position));
        holder.iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                imageShow.showImage(position);
            }
        });
        holder.tvTitle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                imageShow.showDetail(position);
            }
        });
    }
    public ImageShow imageShow;
    public interface ImageShow {
        void showImage(int position);
        void showDetail(int position);
    }
    public void setImageShow(ImageShow imageShow) {
        this.imageShow = imageShow;
    }
    @Override
    public int getItemCount() {
        return titles.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv)
        ImageView iv;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.tv_type)
        TextView tvType;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
